<template>
	<view >
		<web-view :src="linkUrl" v-if="iOS"></web-view>
	</view>
</template>

<script>
	import { staticBaseUrl } from '@/utils/constant.js';
	
	export default {
		data() {
			return {
				type: '',
				staticBaseUrl: staticBaseUrl,
				linkUrl: '',
				iOS: true,
			}
		},
		onLoad(options) {
			console.log('options==',options)
			let title = ''
			if(options.type == '1'){
				title = '用户隐私政策';
				this.linkUrl = this.staticBaseUrl + '/mtUserPrivacy.pdf'
			}
			if(options.type == '2'){
				title = '平台服务协议';
				this.linkUrl = this.staticBaseUrl + '/mtPlatServiceAgreement.pdf'
			}
			this.type = options.type;
			// console.log('d地址===',this.linkUrl)
			uni.setNavigationBarTitle({
				title: title
			});
			uni.getSystemInfo({
				success: (res) => {
					console.log(res)
					if (res.system.includes('iOS')) {
						this.iOS = true;
						// iOS 可直接查看
					} else {
						this.iOS = false;
						// Android 需要下载后再打开
						uni.downloadFile({
							url: this.linkUrl,
							filePath: wx.env.USER_DATA_PATH + '/' + title + '.pdf',
							success: (res) => {
								const path = res.filePath
								// const path = res.tempFilePath;
								uni.openDocument({
									filePath: path,
									fileType: 'pdf',
									success: (res) => {
										uni.navigateBack({
											delta: 1
										});
									},
									fail: (err) => {
										uni.showToast({
											title: '打开文件失败',
											icon: 'none',
											duration: 2000
										});
									}
								});
							},
							fail: (err) => {
								console.log(err);
								uni.showToast({
									title: '下载文件失败',
									icon: 'none',
									duration: 2000
								});
							}
						});
					}
				}
			});
		},
		methods: {
			
		}
	}
</script>

<style>

</style>
